package com.yang.leather.core;

import java.util.Date;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.tepando.upload.Config;
import com.tepando.util.DateUtil;

public final class ApplicationListener implements ServletContextListener {
	private static final String UPLOAD_CONFIG_PATH = "/uploadConfig.xml";

	//日志
	private Logger log = LoggerFactory.getLogger(ApplicationListener.class);
	
	public void contextDestroyed(ServletContextEvent event) {
		
	}

	public void contextInitialized(ServletContextEvent event) {
		long t1=System.currentTimeMillis();
		if(log.isInfoEnabled())  
		{
			log.info("/***************************************");
			log.info("系统初始化开始,时间:"+DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm:ss"));
		}
		
		ServletContext context = event.getServletContext();
		
		Config.initConfig(UPLOAD_CONFIG_PATH, context);//文件上传框架初始化
		
		Constant.PROJECT_REAL_PATH = context.getRealPath("/");
		
		if(log.isInfoEnabled())  
		{
			log.info("系统初始化完成,耗时 "+(System.currentTimeMillis()-t1)+" ms");
			log.info("/***************************************");
		}
	}

}
